<template>
	<view>
		<!-- <view class="black_1">
			<template v-for="(item,index) in tab">
				<view class="text" :class="current == index ? 'text_select':''" @click="select(index)">
					{{item}}
					<view :class="current == index ? 'indicator' :''"></view>
				</view>
			</template>
		</view> -->
		<!-- <view style="height: 50px;width: 100%;"></view> -->
		<view class="black_6">
			<template v-for="(item,index) in list">
				<view class="item" @click="selecItem(item)">
					<view class="left">
						<!-- <view class="line_1">
							<image class="img" src="/static/logo.png"></image>
							<text class="text3">幸运小羊羊</text>
						</view> -->
						<view class="line_1">
							<text class="text1">数量:</text>
							<text class="text2">{{item.num}}</text>
							<text class="text1">{{current == 0?'ZY':'CNY'}}</text>
						</view>
						<view class="line_1">
							<text class="text1">总价:</text>
							<text class="text2">{{item.total_price}}</text>
							<text class="text1">{{current == 0?'CNY':'ZY'}} </text>
						</view>

						<view  v-if="current == 0"   class="line_1">
							<template v-for="(itempay,indexpay) in getbuyCollection(item)">
								<image class="pay_img" src="/static/logo.png"></image>
							</template>
						</view>

					</view>
					<view class="right">
						<view class="line_1">
							<text class="text1">{{getStatusname(item)}}</text>
						</view>
						<view class="line_1">
							<text class="text6"> {{current == 0?'¥':'ZY'}}</text>
							<text class="text3">{{item.unit_price}}</text>
							<text class="text1">/ 单价</text>
						</view>
						<view v-if="current == 0" class="line_1 line_2">
							<view class="text4">查看详情</view>
						</view>
					</view>
				</view>

			</template>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				current: 0,
				tab: ['USDT', '汽油'],
				list: [{}],
				page:1,
				userId:''
			};
		},
		onLoad(opt) {
			this.userId = uni.getStorageSync('userId')
			// this.select(0)
		},
		onShow() {
			this.select(this.current)
		},
		methods: {
			getbuyCollection(item){
				if(item){
					return []
				}
				return item.parse(item.buy_collection.data)
			},
			select(index){
				this.current = index
				this.page =1
				this.list.length =0
				this.getList()
			},
			selecItem(item) {
				if(this.current == 1)
				return
				this.custom.tool.jump(0, 'trading/MyTransaction?userId='+this.userId+"&id="+item.id)
			},
			getList(){
				var json ={
					// account_type:this.current ==0?'usdt':'gasoline',
					type :"all",
					page:this.page
				}
				this.api.http.requests('exchange/lists', json, res => {
					if (res.data && res.data.length > 0) {
						this.list = this.list.concat(res.data)
					}
				}, "POST")
			},
			getStatusname(item){
				//订单状态 -1：已取消(买卖发布人取消订单)，
				// 0：已发布(未买或未卖)，
				// 1：卖方已出售或买方确定购买(待买方付款)，
				// 2：待收款(买方已付款，可申诉)，
				// 3：申述中(卖家未收到款项)，
				// 4：已完成(卖家已确认收款)
				// console.log(item)
				if(item.status == 1 ){
					if(this.userId == item.sell_id){
						return '待买家付款'
					}
					return "待付款"
				}else if(item.status == 2){
					if(this.userId == item.sell_id){
						return '待收款'
					}
					return "待商家确认"
				}else if(item.status == 3){
					return "申述中"
				}else if(item.status == 4){
					if(item.sell_id == this.userId){
						return "已完成收款"
					}
					return "已完成"
				}else if(item.status == -1){
					return '已取消'
				}
			}
		},
		onReachBottom() {
			this.page =this.page+1
			this.getList()
		}
	}
</script>

<style lang="less">
	.black_1 {
		position: fixed;
		width: 100%;
		display: flex;
		background-color: white;
		justify-content: space-between;
		align-items: center;
		padding: 30rpx 0rpx 10rpx 0rpx;
		font-size: 32rpx;
		font-weight: 400;
		color: #969696;
		text-align: center;
		border: 1rpx solid #ECECEC;
		z-index: 99;
		.text {
			width: 50%;
			height: 50rpx;
			padding: 0px 10px;

			.indicator {
				width: 35px;
				height: 4rpx;
				background: #FE903D;
				border-radius: 2px;
				margin:7px auto 0px auto;
			}
		}

		.text_select {
			font-weight: 400;
			color: #FE903D;
		}

	}


	.black_6 {

		padding: 10px  0px;
		.item {
			padding: 10px 20px;
			display: flex;
			justify-content: space-between;
			border-bottom: 2rpx solid #ECECEC;
			align-items: center;

			.left {
				.line_1 {
					font-size: 25rpx;
					font-weight: 400;
					color: #969696;
					margin-bottom: 5px;

					.img {
						vertical-align: middle;
						width: 25px;
						height: 25px;
						border-radius: 50%;
						margin-right: 5px;
					}

					.text2 {
						font-size: 25rpx;
						font-weight: 800;
						color: #262626;
						padding: 0px 10px;
					}

					.text3 {
						margin-top: 5px;
						font-size: 28rpx;
						font-weight: 800;
						color: #333333;
					}

					.pay_img {
						margin-top: 5px;
						
						width: 15px;
						height: 15px;
						margin-right: 5px;
					}
				}
			}

			.right {
				text-align: end;

				.line_1 {
					font-size: 25rpx;
					font-weight: 400;
					color: #969696;
					margin-bottom: 5px;

					.text2 {

						color: #262626;

					}
					.text6{
						color: #FE903D;
					}
					.text3 {
						font-size: 49rpx;
						font-weight: 800;
						color: #FE903D;
					}

					.text4 {
						margin-top: 5px;
						text-align: center;
						background: #FFFFFF;
						border-radius: 4rpx;
						padding: 2px 8px;
						// width: 80px;
						border: 1rpx solid #FE903D;
						font-size: 25rpx;
						font-weight: 400;
						color: #FE903D;
					}

					.text4_action {
						color: #969696;
						border: 1rpx solid #ECECEC;
					}

				}

				.line_2 {
					display: flex;
					justify-content: end;

					.text5 {
						background: #FE903D;
						color: white;
					}
				}
			}
		}
	}
</style>